﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Optimus.Core
{
    public class MemoryMonitor
    {
        public uint UsedMemory = 0;
        public uint TotalMemory = 0;
        public uint Percentage = 0;
        public uint FreeMemory = 0;
        private const uint div = 1048576;
        public uint Original;
        public void InitEx()
        {
            CheckUsedMemory();
            Original = UsedMemory;
        }
        public void CheckUsedMemory()
        {
            UsedMemory = Cosmos.Core.Heap.GetUsedMemory();//Get Used Memory
            UsedMemory = UsedMemory / div;//Convert to MB
        }
        public void GetTotalMemory()
        {
            TotalMemory = Cosmos.Core.CPU.GetAmountOfRAM() + 1;
        }
        public void Monitor()
        {
            CheckUsedMemory();
            GetTotalMemory();
            FreeMemory = TotalMemory - UsedMemory;
            Percentage = (UsedMemory * 100) / TotalMemory;
            Console.WriteLine("Mem Usage: " + UsedMemory.ToString());
            Console.WriteLine("Total Mem: " + TotalMemory.ToString());
            Console.WriteLine("Free Mem:" + FreeMemory.ToString());
        }
    }
}
